package com.lft07.status;

/**
 * Function: 		A {@code TestJoin} 测试线程合并方法<br/>
 * Reason:   		join线程合并，插队<br/>
 * Date:            2021-01-27 14:45<br/>
 * <p>
 * Class Name:      TestJoin<br/>
 * Package Name:    com.lft07.status<br/>
 * @author Laifengting / E-mail:laifengting@foxmail.com
 * @version 1.0.0
 * @since JDK 8
 */
public class TestJoin implements Runnable {
	@Override
	public void run() {
		for (int i = 0; i < 1000; i++) {
			if (i == 100) {
				// 让thread插队
				Thread.yield();
			}
			System.out.println("线程VIP来了。。。" + i);
		}
	}
	
	public static void main(String[] args) {
		// 启动自定义的线程
		TestJoin testJoin = new TestJoin();
		Thread thread = new Thread(testJoin);
		thread.start();
		
		// 主线程
		for (int i = 0; i < 1000; i++) {
			if (i == 200) {
				try {
					// 让thread插队
					thread.join();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
			System.out.println("Main " + i);
		}
		
	}
}
